<template>
  <div class="similar-feature-list">
    <div v-if="selected.assetId" class="tab-title">
      <icon-svg name="iconReturn" @click.native="prev"></icon-svg>
      {{ selected.assetNm }}
    </div>
    <el-input v-model="assetNm" placeholder="输入搜索关键字" @keyup.native.enter="search">
      <i class="el-icon-close" slot="suffix" @click="clearSearch" v-if="assetNm.length"></i>
      <el-button slot="append" @click="getList"><icon-svg name="iconSearch"></icon-svg></el-button>
    </el-input>
    <template v-if="list.length">
      <ul>
        <li v-for="item in list" :key="item.assetId" @click="getList(item)" class="tag-item">
          <div class="asset-name">{{ item.assetNm }}</div>
          <i class="el-icon-arrow-right" v-if="item.assetType !== 1"></i>
          <div class="list-handler" v-if="item.assetType === 1">
            <el-tooltip effect="dark" content="添加" placement="top" :enterable="false">
              <span class="plus" @click.prevent="$emit('addItem', item)"><i class="el-icon-plus"></i></span>
            </el-tooltip>
            <el-tooltip effect="dark" placement="top" :enterable="false">
              <span slot="content">
                口径：{{ item.bizStmt }}
                <template v-if="item.plfmDataDate">
                  <br />
                  <br />
                  数据日期: {{ item.plfmDataDate }}
                </template>
              </span>
              <icon-svg name="iconPreview"></icon-svg>
            </el-tooltip>
          </div>
        </li>
      </ul>
      <el-pagination
        @current-change="handleCurrentChange"
        :current-page="params.currentPageNum"
        :page-size="params.pageSize"
        :pager-count="5"
        background
        layout="total, prev, pager, next"
        small
        :total="totalSize"
      >
      </el-pagination>
    </template>
    <p v-else>{{ loading ? '' : '暂无内容' }}</p>
  </div>
</template>

<script>
export default {
  props: {
    listType: {
      type: Number,
      required: true,
      default: 0
    },
    loading: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      list: [],
      assetNm: '',
      selected: {},
      params: {
        ascs: [],
        descs: [],
        currentPageNum: 1,
        pageSize: 10,
        queryParams: {},
        descPriority: false
      },
      totalSize: 0
    }
  },
  methods: {
    handleCurrentChange(val) {
      this.params.currentPageNum = val
      this.getList(this.selected)
    },
    getList(item = {}) {
      if (item && item.assetType === 1) return
      this.params.queryParams.listType = this.listType
      this.params.queryParams.assetNm = this.assetNm
      this.params.queryParams.assetType = item.assetType || (this.selected.assetType ? this.selected.assetType : 1)
      if (item.assetType === 3 || (this.selected.assetType && this.selected.assetType === 3)) {
        this.params.queryParams.assetId = item.assetId || this.selected.assetId
      }
      this.$emit('toggleLoading', true)
      this.$ajax({
        url: this.$ajax.setUrl('tagFactory/pageList'),
        method: 'get',
        params: this.$ajax.setParams(this.params)
      }).then(({ data }) => {
        if (data && data.code === '0') {
          this.list = data.data.records
          this.totalSize = data.data.totalSize
          if (item.assetType === 3) this.selected = item
        } else {
          this.$message.error(data.data || data.msg)
        }
        this.$emit('toggleLoading', false)
      })
    },
    search() {
      this.params = {
        ascs: [],
        descs: [],
        currentPageNum: 1,
        pageSize: 10,
        queryParams: {},
        descPriority: false
      }
      this.getList()
    },
    clearSearch() {
      this.assetNm = ''
      this.getList()
    },
    prev() {
      this.assetNm = ''
      this.selected = {}
      this.params = {
        ascs: [],
        descs: [],
        currentPageNum: 1,
        pageSize: 10,
        queryParams: {},
        descPriority: false
      }
      this.getList()
    }
  }
}
</script>

<style lang="scss">
.similar-feature-list {
  color: #455fbc;
  .asset-name {
    width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .tag-item {
    padding: 0 60px 0 20px;
    line-height: 40px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
    position: relative;
    &:hover {
      background-color: #c0d2f6;
      &:not(.tag-disabled):before {
        width: 10px;
        height: 10px;
        content: '';
        border: 2px solid rgba(#000, 0.3);
        background-color: #a8fff9;
        border-radius: 50%;
        position: absolute;
        top: 15px;
        left: 5px;
      }
      &.tag-disabled .icon-disabled {
        display: block;
      }
    }
    i {
      position: absolute;
      top: 15px;
      right: 15px;
    }
    .list-handler {
      position: absolute;
      top: 0;
      right: 10px;
      .plus {
        display: inline-block;
        width: 18px;
        height: 18px;
        margin-top: -5px;
        border: 1px solid #5f8eec;
        color: #5f8eec;
        line-height: 15px;
        text-align: center;
        border-radius: 50%;
        vertical-align: middle;
        i {
          font-size: 12px;
          position: static;
        }
      }
      svg {
        width: 16px;
        height: 16px;
        color: #455fbc;
        margin: -5px 5px 0 10px;
        vertical-align: middle;
      }
    }
  }
  .tab-title {
    font-size: 15px;
    font-weight: bold;
    padding: 5px 0 10px 45px;
    color: #455fbc;
    position: relative;
    .el-breadcrumb__item.normal .el-breadcrumb__inner {
      font-weight: normal;
    }
    .el-breadcrumb__inner {
      font-size: 15px;
      font-weight: bold;
      color: #455fbc;
      &:hover {
        color: #455fbc;
      }
    }
    svg {
      width: 18px;
      height: 18px;
      position: absolute;
      left: 20px;
      top: 2px;
      cursor: pointer;
    }
  }
  p {
    padding: 0 20px;
    margin: 10px 0 20px 0;
  }
  .el-pagination {
    padding: 2px 20px;
    white-space: normal;
  }
  .el-pagination.is-background .el-pager li:not(.disabled).active {
    background-color: #455fbc;
  }
}
</style>
